package com.zerdoor.controller;

import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.BidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project: acgplat
 * Module ID: 007
 * Comments: 招投标管理
 * JDK version used: JDK1.7
 * Namespace: controller
 * Author：xiaoji
 * Create Date：2014-11-24
 * Modified By：   <修改人中文名或拼音缩写>
 * Modified Date:  <修改日期，格式:YYYY-MM-DD>
 * Why & What is modified  <修改原因描述>
 * Version:                  <版本号>
 */
@Controller
@RequestMapping("bid")
public class BidController {

    @Autowired
    private BidService bidService;

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(){return "/bid/view";}

    /**
     * 获取任务数据
     * @param request
     * @param page 当前页
     * @param rows 每页显示条数
     * @return
     */
    @RequestMapping(value = "/view",method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> view(HttpServletRequest request,int page,int rows){
        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("title",request.getParameter("title"));
        List<Map<String, Object>> list = bidService.getItemInfo(result);
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 翻译为英文
     */
    @RequestMapping(value = "/translationEn",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> translationEn(int itemId,HttpServletRequest request){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result.put("itemId",itemId);
            result.put("titleEn",request.getParameter("titleEn"));
            result.put("descriptionEn",request.getParameter("descriptionEn"));

            bidService.updateEn(result);
        } catch (Exception e) {
            result.put("errormsg", "翻译失败");
        }
        return result;
    }

    /**
     * 翻译为中文
     */
    @RequestMapping(value = "/translationCn",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> translationCn(int itemId,HttpServletRequest request){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result.put("itemId",itemId);
            result.put("titleCn",request.getParameter("titleCn"));
            result.put("descriptionCn",request.getParameter("descriptionCn"));

            bidService.updateCn(result);
        } catch (Exception e) {
            result.put("errormsg", "翻译失败");
        }
        return result;
    }
}
